# 第三方库
import re
from fastapi import APIRouter

# 项目内库
from best_seller.services.crawl_svc import crawl_svc
from best_seller.spiders.product_link_spider import ProductLinkSpider


router = APIRouter()

@router.post("/start_crawl/")
def crawl_product_links(url: str):
    crawl_svc.crawl(ProductLinkSpider.__name__, url)
    crawl_svc.run_now()
    return {"message": "抓取服务已启动"}



@router.post("/restart_tasks/")
def restart_tasks(task_ids: list[str]):
    crawl_svc.restart_tasks(task_ids)
    crawl_svc.start_timer()
    return {"message": "批量任务重启成功"}